package com.example.android.adapters

import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.android.R
import com.example.android.models.Announce
import com.example.android.utils.MyRecyclerViewAdapter
import java.time.format.DateTimeFormatter

/**
 * @ClassName AnnounceRecyclerViewAdapter
 * @Author Ryan Kamanri
 * @Date 2022/6/1
 * @Description
 **/
class AnnounceRecyclerViewAdapter(val context: Context, private val announceList: ArrayList<Announce>) :
    MyRecyclerViewAdapter<Announce, AnnounceRecyclerViewAdapter.ViewHolder>(announceList) {

    class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val title = itemView.findViewById<TextView>(R.id.announce_item_title)
        val day = itemView.findViewById<TextView>(R.id.announce_item_day)
        val year_month = itemView.findViewById<TextView>(R.id.announce_item_year_month)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        return ViewHolder(super.CreateView(parent, R.layout.view_announce_item))
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val item = announceList[position]
        val day = item.time.substring(8, 10)
        val month = item.time.substring(5, 7)
        val year = item.time.substring(0, 4)
        holder.title.text = item.title
        holder.day.text = day
        holder.year_month.text = "$year/$month"
    }
}